package it.uniroma2.art.owlart.langsearch.analysis;

import java.io.Reader;

import org.apache.lucene.analysis.ASCIIFoldingFilter;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.LowerCaseFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.standard.StandardFilter;
import org.apache.lucene.util.Version;

/**
 * a filter which makes the analysis:
 * <ul>
 * <li>insensitive to diacritics, by using {@link ASCIIFoldingFilter}</li>
 * <li>insensitive to case, by using {@link LowerCaseFilter}</li>
 * </ul>
 * and applies filters above to a {@link StandardFilter}
 * 
 * @author Armando Stellato <a href="mailto:stellato@info.uniroma2.it">stellato@info.uniroma2.it</a>
 *
 */
public final class ASCIIFoldingSingleCharLabelSeparatorTokenAnalyzer extends Analyzer {

	Version ver;
	
	public ASCIIFoldingSingleCharLabelSeparatorTokenAnalyzer(Version ver) {
		this.ver = ver;  
	}
	
	public TokenStream tokenStream(String fieldName, Reader reader) {
		TokenStream result = 
			// TODO ISOLatin1AccentFilter to be used in old version of Lucene
			new ASCIIFoldingFilter (
				new LowerCaseFilter(ver, 
					new StandardFilter(ver,										
						new SingleCharLabelSeparatorTokenizer(ver, reader)
						// new KeywordTokenizer(reader)
					)
				)		
			);
		return result;
	}
}
